<template>
    <el-dialog custom-class="dialog-resource" top="1%" title="资源中心" :visible.sync="dialogResourceVisible" @close="closeDialogResource">
      <iframe scrolling="auto" allowtransparency="true" style="width: 95%;height: 90%; position: absolute" :src="url" frameborder="0" ></iframe>
    </el-dialog>
</template>

<script>
import store from '@/store'
export default {
  name: 'DialogResource',
  props: ['dialogResourceVisible'],
  data() {
    return {
      url: '',
      select: null
    }
  },
  created() {
    var _this = this
    var urlArray = window.location.href.split('/')
    var url = urlArray[0] + '//' + urlArray[2] + '/resource-center?isolate=merchant'
    url += '&isolate_id=' + store.getters.id
    url += '&token=' + store.getters.token
    this.url = url
    window.onmessage = function(e) {
      _this.select = e.data
      _this.closeDialogResource()
      _this.selectResourceClick()
    }
  },
  methods: {
    closeDialogResource() {
      this.dialogResourceVisible = false
      this.$emit('closeDialogResource', { dialogResourceVisible: this.dialogResourceVisible })
    },
    selectResourceClick() {
      this.$emit('selectResourceClick', { select: this.select })
    }
  }
}
</script>
<style>
  .dialog-resource{
    width: 90%;
    height: 90%;
    position: relative;
    .el-dialog__body {
      padding: 5px;
    }
    .el-dialog__header {
      padding-bottom: 0px;
    }
  }
</style>
